package org.compiere.process;

import java.io.File;
import java.math.BigDecimal;
import java.util.Properties;

import jxl.Workbook;
import jxl.write.Label;
import jxl.write.Number;
import jxl.write.WritableSheet;
import jxl.write.WritableWorkbook;

import org.adempiere.exceptions.AdempiereException;
import org.compiere.apps.ADialog;
import org.compiere.model.MAttachmentEntry;
import org.compiere.util.Env;
import org.compiere.util.Msg;

import extend.org.compiere.utils.Util;

public class MM_Purchase {

	private Properties m_ctx;
	BigDecimal OrderID = null;	
	
	public MM_Purchase(BigDecimal OrderID) {
		this.OrderID = OrderID;
		String result = toExcel();
	}
	
	private String toExcel() {
		

		Label label;
		Number number;
		
		
		m_ctx = Env.getCtx();
		
		String templateName = "MM_Purchase_tmpl.xls";
		MAttachmentEntry entry = Util.getAttachment(null, m_ctx, templateName);
		if (entry == null)
			throw new AdempiereException(Msg.translate(m_ctx,
					"NotFoundTemplate") + " " + templateName);

		File templateCopy = new File(Util.localFilePath + "MM_Purchase.xls");
		File temporaryFile = entry.getFile(Util.localFilePath + templateName);
		Workbook tableBook = null;
		WritableWorkbook copy = null;
		WritableSheet sheet = null;
		try {
			tableBook = Workbook.getWorkbook(temporaryFile);
			copy = Workbook.createWorkbook(templateCopy, tableBook);
			sheet = copy.getSheet(0);
		} catch (Exception e) {
			ADialog.error(999, null, "Error tableBook. " + e.getMessage());
			return "Error tableBook.";
		}
		
		return "";
		
	}


	
}
